/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jmeshless;


import FEMShapeFunction1D.FEMShapeFunction1D1;
import MF1DSolver.MF1DSolverCoupled;
import MeshlessShapeFunctions.JGaussian;
import MeshlessShapeFunctions.JMeshlessInterpolationFunction1D;
import MeshlessShapeFunctions.JMeshlessInterpolationFunction1DCoupled2;
import MeshlessShapeFunctions.JMeshlessInterpolationFunctionLiu;
import MeshlessShapeFunctions.Particle;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.yourorghere.Node;
import org.yourorghere.Triangle;

/**
 *
 * @author mark
 */
public class MainCoupled {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException {

        int nn = 10;
        ArrayList<Particle> ls1D = new ArrayList<Particle>();
        ArrayList<JMeshlessInterpolationFunction1DCoupled2> MeshlessShapeList = new ArrayList<JMeshlessInterpolationFunction1DCoupled2>();
        
        
        ArrayList<FEMShapeFunction1D1> fem = new ArrayList<FEMShapeFunction1D1>();
        fem.add(new FEMShapeFunction1D1(0.0, 0.09));
        fem.add(new FEMShapeFunction1D1(1.0, 0.09));

        double a =0,b=1;
        double h = (b-a)/(double)nn;
        for (int i = 1; i <nn; i++) {
            ls1D.add(new Particle(a+h*i, 0, i-1));
            MeshlessShapeList.add(new JMeshlessInterpolationFunction1DCoupled2(1, a+i*h, 2.6*h, new JGaussian(), fem));
            //MeshlessShapeList.add(new JMeshlessInterpolationFunction1D(1, a+i*h, 1.33*h, new JStKernel()));
            //System.out.print(ls1D.get(i).getX()+"\t");
        }
        System.out.println();
        System.out.println("=========================================================");

        MF1DSolverCoupled solver = new MF1DSolverCoupled();
            solver.setfString("100");
            solver.setwString("100");
            solver.setqString("0");
            solver.setpString("1");
        solver.setListOfShapeFunction(MeshlessShapeList);
        solver.setNodeList(ls1D);
        solver.generate();
        //double[] res = solver.solvePenalty();
        //double[] res = solver.solveLagrangeMulti();
        double[] res = solver.solve();
        double x = 0;
        while(x<=1.0001){
            double tmp = 0.0;
            for (int j = 0; j <res.length-2; j++) {
                tmp+= MeshlessShapeList.get(j).calculate(x)*res[j];
            }
            System.out.print(x+"\t"+tmp+"\n");
            x+=0.01;
        }
        System.out.println();
        System.out.println("=========================================================");
        XYSeries series1 = new XYSeries("розвязок методом штрафу", true, true);
            x = 0;
            while(x<=1.0001){
                double tmp = 0.0;
                for (int j = 0; j <res.length; j++) {
                    tmp+= MeshlessShapeList.get(j).calculate(x)*res[j];
                }
                series1.add(x,tmp);
                x+=0.01;
            }

            NewOkCancelDialog dialog = new NewOkCancelDialog(null, false, new XYSeriesCollection(series1));
            dialog.setLocationRelativeTo(null);
            //dialog.setUndecorated(true);
            dialog.setVisible(true);

    }

    public static ArrayList<Double> Results;
    public static ArrayList<Node> NodeList;
    public static ArrayList<Triangle> TrList;
    public static JMeshlessInterpolationFunctionLiu jm;
    public static JMeshlessInterpolationFunction1D jm1D;
}
